Choose an Option

Author

Alois Tilloy

Demo of the Transformed-Stationary Extreme Value Analysis with discharge data from the HERA hydrological reanalysis

Step 1: load the hydrological time series and associated metadata

Ebro @ Zaragoza:

  • Total length: 930 km
  • Mean flow: 197 m3/s
  • Short description: The Ebro is Spain’s longest river, with low and high water levels alternating throughout the year, influenced by winter snowmelt and summer evaporation/human usage. The river is vital for agriculture.
  • More: Wiki

Ardèche @ Saint Martin:

  • Total length: 120 km
  • Mean flow: 50 m3/s
  • Short description: The Ardèche is mediterranean river mostly known for tourism due to its scenic gorges. The river is known for its extreme autumn floods during the so called “épisodes cévenols”.
  • More: Wiki

Rhône @ Lyon:

  • Total length: 813 km
  • Mean flow: 507 m3/s
  • Short description: The Rhône is France’s most powerful river, characterized by a significant seasonal variation in flow rates. The Rhône is crucial for transportation, hydropower generation, and irrigation in the region.
  • More: Wiki

Danube @ Vienna:

  • Total length: 2850 km
  • Mean flow: 1800 m3/s
  • Short description: The Danube is the longest river in the European Union. It is an important waterway for international trade, connecting several countries in Central and Eastern Europe.
  • More: Wiki

We choose the Ardèche for this example.

Code
data=Ardeche$data
longitude=Ardeche$river$lon
latitude=Ardeche$river$lat
timeStamps=data$time

Location of the selected river:

Plot of the original timeseries

Hydrograph of river Ardeche

Different preprocessing depending on which hazard is studied:

  • Flood:
    • no transformation
    • minimum distance between two peaks: 10 days
    • analysis performed on daily maximum discharge
  • Drought:
    • reversed transformation
    • minimum distance between two peaks: 30 days
    • analysis performed on 7-days moving averaged discharged

Step 2: Run TSEVA for flood

Code
haz = "flood"

dt1=min(diff(data$time),na.rm=T)
dt=as.numeric(dt1)
tdim=attributes(dt1)$units
if (tdim=="hours") dt=dt/24
if (dt==1){
  timeDays=data$time
}else{
  timeDays=unique(as.Date(data$time))
}
if (haz=="drought"){
  
  minPeakDistanceInDays=30
  tail="low"
  #7 day average flow for drought analysis
  WindowSize=7
  names(data)=c("date","Qs")
  if (tdim=="hours") dt=dt/24
  nRunMn = ceiling(WindowSize/dt);
  colnames(data)
  data$Q7=rollmean(data$Qs,nRunMn, align = "right", fill=NA)
  
  if (!exists("trans")){trans="rev"}
  print(paste0(trans," transformation used for low flows"))
  
  series=data.frame(data$date,data$Q7)
  
}else if (haz=="flood"){
  tail="high"
  percentile=95
  minPeakDistanceInDays=10
  series <- max_daily_value(data)
  

}
timeAndSeries=series
names(timeAndSeries)=c("timestamp","data")

tsm=1/dt
series=timeAndSeries[,2]
timeWindow = 365.25*30; #time windows in days, the correction is done within the functions
windowSize=366

timeStamps=timeAndSeries$timestamp
transftypes=c("ori","rev")
trendtypes=c("trend","trendPeaks")
trendtrans=expand.grid(transftypes,trendtypes)
trendtrans = data.frame(trendtrans)
names(trendtrans)=c("transformation","trend method")

tt=3
print(trendtrans[tt,])
  transformation trend method
3            ori   trendPeaks
Code
Nonstat<-TsEvaNs(timeAndSeries, timeWindow, transfType=trendtrans[tt,2], ciPercentile= 90, minPeakDistanceInDays = minPeakDistanceInDays, tail, tail = tail, trans=trendtrans[tt,1])
nonStationaryEvaParams=Nonstat[[1]]
stationaryTransformData=Nonstat[[2]]

for more details on the different transformation and trend methods, the reader can refer to the RtsEva package documentation: https://cran.r-project.org/web/packages/RtsEva/RtsEva.pdf

Step 4: Plot results for flood

Timeseries with peaks and evolving GPD density

Return Level curve in 1951

Curve beam (all curves from 1951 to 2020)

Step 5: Run TSEVA for drought

Code
haz = "drought"

dt1=min(diff(data$time),na.rm=T)
dt=as.numeric(dt1)
tdim=attributes(dt1)$units
if (tdim=="hours") dt=dt/24
if (dt==1){
  timeDays=data$time
}else{
  timeDays=unique(as.Date(data$time))
}
if (haz=="drought"){
  
  minPeakDistanceInDays=30
  tail="low"
  #7 day average flow for drought analysis
  WindowSize=7
  names(data)=c("date","Qs")
  if (tdim=="hours") dt=dt/24
  nRunMn = ceiling(WindowSize/dt);
  colnames(data)
  data$Q7=rollmean(data$Qs,nRunMn, align = "right", fill=NA)
  
  if (!exists("trans")){trans="rev"}
  print(paste0(trans," transformation used for low flows"))
  
  series=data.frame(data$date,data$Q7)
  
}else if (haz=="flood"){
  tail="high"
  percentile=95
  minPeakDistanceInDays=10
  series <- max_daily_value(data)
  

}
[1] "ori transformation used for low flows"
Code
timeAndSeries=series
names(timeAndSeries)=c("timestamp","data")
timeStamps=timeAndSeries$timestamp

tt=4
print(trendtrans[tt,])
  transformation trend method
4            rev   trendPeaks
Code
Nonstat<-TsEvaNs(timeAndSeries, timeWindow, transfType=trendtrans[tt,2], ciPercentile= 90, minPeakDistanceInDays = minPeakDistanceInDays, tail, tail = tail, trans=trendtrans[tt,1])
nonStationaryEvaParams=Nonstat[[1]]
stationaryTransformData=Nonstat[[2]]

Step 6: Plot results for drought

Timeseries with peaks and evolving GPD density

Return Level curve in 1951

Curve bean (all curves from 1951 to 2020)

# Load the shiny package
library(shiny)

# Define the UI
ui <- fluidPage(
  selectInput("option", "Choose an option:",
              choices = list("Option 1" = 1,
                             "Option 2" = 2,
                             "Option 3" = 3,
                             "Option 4" = 4))
)

# Define the server function
server <- function(input, output) {
 # Create a reactive expression for the selected option
  selected_option <- reactive({
    input$option
  })

  # Use the selected option in your code
  output$result <- renderText({
    if (selected_option() == 1) {
      # Perform operations for Option 1
      "You selected Option 1"
    } else if (selected_option() == 2) {
      # Perform operations for Option 2
      "You selected Option 2"
    } else if (selected_option() == 3) {
      # Perform operations for Option 3
      "You selected Option 3"
    } else if (selected_option() == 4) {
      # Perform operations for Option 4
      "You selected Option 4"
    }
  })
}

# Run the app
shinyApp(ui, server)

Shiny applications not supported in static R Markdown documents